import Vue from 'vue';
import App from './App';
import request from "./static/libs/request";
import config from "./static/libs/config";
import {
	Storage
} from "./static/libs/utils";
import store from './store'

Vue.config.productionTip = false
Vue.prototype.$store = store
Vue.prototype.backTo = function(){
	uni.navigateBack({
	        delta: 1,
	        animationType: 'pop-out',
	        animationDuration: 200
	    });
}

App.mpType = 'app'

new Vue({ ...App,store
}).$mount();

request.defaults.baseURL = config.url.http + config.path.api;


request.interceptors.request.use((params) => {
	params.data || (params.data = {});
	const authorization = Storage.get("authorization");
	authorization && (params.header.token = authorization);

	for (const key in params.data) {
		if ([undefined, null, NaN].includes(params.data && params.data[key])) {
			delete params?.data[key];
		}
	}
	return params;
});

request.interceptors.response.use(res => res)

Vue.prototype.$config = config;
Vue.prototype.$request = request;
